<template>
  <div id="app">
    <mt-header fixed title="商场">
      <span slot="left">
        <mt-button icon="back" @click="back" v-show="flag">返回</mt-button>
      </span>
    </mt-header>
    <transition name="run" mode="">
      <router-view></router-view>
    </transition>

    <nav class="mui-bar mui-bar-tab">
      <router-link to="/home" class="mui-tab-item">
        <span class="mui-icon mui-icon-home"></span>
        <span class="mui-tab-label">首页</span>
      </router-link>
      <router-link to="/member" class="mui-tab-item">
        <span class="mui-icon mui-icon-contact"></span>
        <span class="mui-tab-label">会员</span>
      </router-link>
      <router-link to="/car" class="mui-tab-item">
        <span class="mui-icon mui-icon-extra mui-icon-extra-cart"
          ><span class="mui-badge" id="badge">{{
            $store.getters.getAllCount
          }}</span></span
        >
        <span class="mui-tab-label">购物车</span>
      </router-link>
      <router-link to="/search" class="mui-tab-item">
        <span class="mui-icon mui-icon-search"></span>
        <span class="mui-tab-label">搜索</span>
      </router-link>
    </nav>
  </div>
</template>

<script>
import mui from "../static/mui/js/mui.js";
export default {
  data() {
    return {
      flag: false,
    };
  },
  created() {
    this.flag = this.$route.path == "/home" ? false : true;
  },
  mounted() {
    mui("body").on("tap", "a", function() {
      document.location.href = this.href;
    });
  },
  methods: {
    back() {
      this.$router.go(-1);
    },
  },
  watch: {
    "$route.path": function(newVal) {
      if (newVal == "/home") {
        this.flag = false;
      } else {
        this.flag = true;
      }
    },
  },
};
</script>
<style lang="scss">
* {
  touch-action: pan-y;
}
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  padding-top: 40px;
  //overflow-x: hidden;
}
.run-enter {
  opacity: 0;
  transform: translateX(100%);
}
.run-leave-to {
  opacity: 0;
  transform: translateX(-100%);
  position: absolute;
}
.run-enter-active,
.run-leave-active {
  transition: all 0.5s ease;
}
.mint-header {
  z-index: 99;
}
.mui-bar-tab .mui-tab-item .mui-active {
  color: #007aff;
}
.mui-bar-tab .mui-tab-item {
  display: table-cell;
  overflow: hidden;
  width: 1%;
  height: 50px;
  text-align: center;
  vertical-align: middle;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: #929292;
}
.mui-bar-tab .my-tab-item .mui-icon {
  top: 3px;
  width: 24px;
  height: 24px;
  padding-top: 0;
  padding-bottom: 0;
}
</style>
